<script setup>
import useTable from "@/utils/useTable";
import {http} from "@/api";
import {onMounted, ref} from "vue";

/**
 * 表格
 * @type {Ref<UnwrapRef<*[]>>}
 */
const {
  searchParams,
  pageNo,
  pageSize,
  total,
  changePage,
  changeSize,
  dataSource,
  search,
  reset,
} = useTable({
  requestFn: http.message,
  routerPre: 'message',
  params: {
    start_date: '',
    end_date: '',
    status: ''
  }
})
</script>


<template>
  <PageMain title="聊天记录">
    <el-form label-suffix="：" inline>
      <el-form-item label="消费状态">
        <el-select v-model="searchParams.status" style="width: 200px">
          <el-option label="全部" value=""></el-option>
          <el-option label="是" value="1"></el-option>
          <el-option label="否" value="0"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="开始日期">
        <el-date-picker type="date" v-model="searchParams.start_date" style="width: 200px" filterable>
        </el-date-picker>
      </el-form-item>
      <el-form-item label="结束日期">
        <el-date-picker type="date" v-model="searchParams.end_date" style="width: 200px" filterable>
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="search">查询</el-button>
        <el-button @click="reset">重置</el-button>
      </el-form-item>
    </el-form>
    <div class="table-box">
      <el-table :data="dataSource">
        <el-table-column label="创建时间" prop="create_time">
        </el-table-column>
        <el-table-column label="来源" prop="platform">
          <template #default="{row}">
            <el-tag v-if="row.platform" type="success">{{ row.platform }}</el-tag>
            <el-tag v-else type="info">未知</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="query" prop="query" min-width="160">
        </el-table-column>
        <el-table-column label="answer" prop="answer" min-width="400">
        </el-table-column>
        <el-table-column label="C端用户" prop="user">
        </el-table-column>
        <el-table-column label="是否消费" prop="status">
          <template #default="{row}">
            <el-tag v-if="row.status === 1" type="success">是</el-tag>
            <el-tag v-else type="danger">否</el-tag>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
          v-model:current-page="pageNo"
          v-model:page-size="pageSize"
          :page-sizes="[10, 50, 100, 200]"
          background
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
          @size-change="changeSize"
          @current-change="changePage"
      />
    </div>
  </PageMain>
</template>

<style scoped lang="scss">

</style>
